export default {
  data() {
    return {
      // 是否为iphone x
      isIphonex: false,
      // 是否为Ios
      isIos: false,
    };
  },
  mounted() {

  },
  methods: {
    /*返回按钮设置*/
    goBack: function () {
      // this.setSlide();
      if (this.$route.query.native == 0) {
        this.$router.go(-1);
      } else if (this.$route.query.backHref == 1) {
        window.history.back();
      } else {
//      if (this.$route.query.router && this.$route.query.router.indexOf('native=0') > -1) {
//        this.$router.go(-1);
//      } else {
//       this.closeBrowser();
//      }
      }
    },

    toast: function (msg, time) {
      let timer;
      time = time ? time : 1500;
      let toast = document.getElementsByClassName('toast-alert')[0];
      if (toast) {
        clearTimeout(timer);
        document.body.removeChild(toast);
      }
      let newToast = document.createElement("div");
      newToast.className = 'toast-alert align-c';
      newToast.innerHTML = "<p class='con'>" + msg + "</p>"
      document.body.appendChild(newToast);
      timer = setTimeout(function () {
        document.body.removeChild(newToast);
      }, time);
    },

    /*获取token*/
    getToken: function () {
      let token, intoToken = this.$route.query.token;
      if (intoToken) {
        token = intoToken;
      } else {
        token = this.getCookie('intoToken');
      }
      return token;
    },


    /*表单验证*/
    checkForm: function (firstName,lastName,chineseName,eMail,phone,passWord,IDNumber,type) {
      /*邮箱正则表达式*/
      var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
      /*中文拼音验证*/
      var regname = "^[A-Za-z]+$"

      if(!firstName || !lastName){
        this.toast("姓与名不能为空")
        return false
      }else if((firstName.search(new RegExp(regname))) || lastName.search(new RegExp(regname))){
        this.toast("姓与名请用中文拼音填写")
        return false;
      }
      if(!eMail){
        this.toast("邮箱不能为空")
        return false
      }else if(eMail.search(new RegExp(regu)) == -1){
        this.toast("电子邮箱格式不对")
        return false
      }

      if(type == 2){
        /*账户信息*/
        if(!phone){
          this.toast("联系电话不能为空")
          return false
        }else if(!/^1(3|4|5|7|8)[0-9]\d{8}/.test(phone)){
          this.toast("联系电话格式")
          return false
        }
        if(!passWord){
          this.toast("密码不能为空")
          return false
        }else if(!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test(passWord)){
          this.toast("密码格式不对，请输入6-16位数字+字母组合")
          return false
        }
      }

      // --------------------------------------------

      if(type == 1){
        /*个人信息*/
        if(!chineseName){
          this.toast("中文姓名不能为空")
          return false
        }else if(!/^[\u2E80-\u9FFF]+$/.test(chineseName)){
          this.toast("中文姓名格式不对")
          return false
        }
        if(!IDNumber){
          this.toast("证件号码不能为空")
          return false
        }else if(!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(IDNumber)){
          this.toast("证件号码格式不对")
          return false
        }
      }
      return true
    }
  }
};
